<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>注册登录</title>
    <link rel="stylesheet" href="login.css">
    <script src="../src/static/jquery.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">

</head>

<body>
<div class="m-login-bg">
    <div class="m-login">
        <h3 style="color: #3569e8">来查查健康</h3>
        <div class="m-login-warp">
            <form class="layui-form">
                <div class="layui-form-item">
                    <input type="text" name="phone" required lay-verify="required" placeholder="手机号码" autocomplete="off"
                           class="layui-input" value="" id="phone">
                </div>
                <div class="layui-form-item">
                    <div class="row">
                        <div class="layui-col-xs6 layui-col-md6">
                            <input type="text" name="password" required lay-verify="required" placeholder="验证码"
                                   autocomplete="off" class="layui-input" id="password1">
                        </div>
                        <div class="layui-col-xs5 layui-col-xs-offset1 layui-col-md4 layui-col-md-offset2">
                            <input type="button" class="obtain generate_code layui-btn" value=" 获取验证码"
                                   onclick="settime(this);" id="YZM">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item anniu">
                    <div class="layui-inline anniu">
                        <button class="layui-btn layui-btn-normal anniu" type="button" lay-submit lay-filter="login">
                            登录
                        </button>
                    </div>
                    <!--<div class="layui-inline">-->
                    <!--<button type="button" onclick="tiaozhuan()" class="layui-btn layui-btn-primary">注册</button>-->
                    <!--</div>-->
                </div>
            </form>
        </div>
        <!--<p class="copyright">版权所有 Copyright2017 All Rights Reserved-->
            <!--上海定希自有设备租赁有限公司 <a href="http://www.miitbeian.gov.cn/">沪ICP备17052837号-1</a></p>-->
    </div>
</div>
<script src="../WeChat/layuiAdmin-master/static/admin/layui/layui.js"></script>
<!--<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>-->
<script>

    //    倒计时start
    var countdown = 60;

    function settime(val) {
        if (countdown == 0) {
            val.removeAttribute("disabled");
            val.value = "获取验证码";
            countdown = 60;
            return false;
        } else {
            val.setAttribute("disabled", true);
            val.value = "重新发送" + countdown;
            countdown--;
        }
        setTimeout(function () {
            settime(val);
        }, 1000);
    }


    layui.use(['form', 'layedit', 'laydate'], function () {

        var form = layui.form(),
            layer = layui.layer;




        $('#YZM').click(function () {

            var phone = document.getElementById('phone').value;
            if(!(/^1[34578]\d{9}$/.test(phone))){
                alert("手机号码有误，请重填");
                return false;
            }else{
                $.ajax({
                    url: '/api/getSmsCode',
                    data: {phone:phone},
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 1) {
                            alert("获取验证码失败，请刷新页面重新获取")
                        }
                    }
                });
            }
        });

        form.on('submit(login)', function (data) {
            var phone = document.getElementById('phone').value;

            $.ajax(
                {
                    url: '/api/Reportlogin',
                    data: data.field,
                    type: 'POST',
                    dataType: 'json',
                    success: function (res) {
                        if (res.code === 0) {
                            location.href = '/putIn/HealthReport.html?phone='+phone;
                        } else if (res.code === 1 || res.code === 2) {
                            layer.msg(res.msg);
                        }
                    }
                }
            );
            return false;
        });

    });

</script>
</body>

</html>